﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RemoteTestRunner.UnitTesting;

namespace RemoteTestRunner.RTRDiagnosisTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class DataDrivenSampleClean
    {
        public DataDrivenSampleClean()
        {
            ////
            // TODO: Add constructor logic here
            ////
        }

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        private static MultiAssertTestClassHelper _testClassHelper;

        #region Additional test attributes
        ////
        // You can use the following additional attributes as you write your tests:
        ////
        // Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            _testClassHelper = new MultiAssertTestClassHelper("DataDrivenSample2", testContext);
        }

        ////
        // Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup()]
        public static void MyClassCleanup()
        {
            _testClassHelper.Dispose();
        }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        [DeploymentItem("RTRDiagnosisTests\\TestDataClean.xls")]
        [DataSource("DataDrivenSampleSourceClean")]
        public void TestMethod1_Clean()
        {
            // Setup function helper
            using (var functionHelper = _testClassHelper.GetFunctionHelper(TestContext))
            {
                // Setup inputs
                functionHelper
                    .AddInput("InputColumn")
                    .AddInput("InputColumn2", TestContext.DataRow["InputColumn2"]);

                // Exercise code.  This would normally be the calls to your business methods
                int input1 = functionHelper.FieldValue<int>("InputColumn");
                int input2 = Convert.ToInt32(TestContext.DataRow["InputColumn2"]);

                int actualSum;
                int actualDifference;
                double actualDivision;

                actualSum = input1 + input2;
                actualDifference = input1 - input2;
                actualDivision = Convert.ToDouble(input1) / Convert.ToDouble(input2);

                // Assert the business results
                functionHelper
                    .AddOutput(DateTime.Now, "Time", "CurrentTime")
                    .AreEqual<int>(actualSum, "Sum test int", "OutputColumn1")
                    .AreEqual<int>(Convert.ToInt32(TestContext.DataRow["OutputColumn2"]), actualDifference, "Difference test", "OutputColumn2")
                    .AreEqual<double>(TestContext.DataRow["OutputColumn3"], actualDivision, "Division test", "OutputColumn3");
            }
        }

        [TestMethod]
        [DeploymentItem("RTRDiagnosisTests\\TestDataClean.xls")]
        [DataSource("DataDrivenSampleSourceClean")]
        public void TestMethod2_Clean()
        {
            // Setup function helper
            using (var functionHelper = _testClassHelper.GetFunctionHelper(TestContext))
            {
                // Setup inputs
                functionHelper
                    .AddInput("InputColumn")
                    .AddInput("InputColumn2", TestContext.DataRow["InputColumn2"]);

                // Exercise code.  This would normally be the calls to your business methods
                int input1 = functionHelper.FieldValue<int>("InputColumn");
                int input2 = Convert.ToInt32(TestContext.DataRow["InputColumn2"]);

                int actualSum;
                int actualDifference;
                double actualDivision;

                actualSum = input1 + input2;
                actualDifference = input1 - input2;
                actualDivision = Convert.ToDouble(input1) / Convert.ToDouble(input2);

                // Assert the business results
                functionHelper
                    .AreEqual<int>(actualSum, "Sum test int", "OutputColumn1")
                    .AreEqual<int>(Convert.ToInt32(TestContext.DataRow["OutputColumn2"]), actualDifference, "Difference test", "OutputColumn2")
                    .AreEqual<double>(TestContext.DataRow["OutputColumn3"], actualDivision, "Division test", "OutputColumn3");
            }
        }
    }
}